home *** CD-ROM | disk | FTP | other *** search
-
- /* @(#)main.c 1.25 91/11/13
- *
- * Main routine for the reve program.
- *
- * Copyright (C) 1990, 1991 - Rich Burridge & Yves Gallot.
- * All rights reserved.
- *
- * Permission is granted to copy this source, for redistribution
- * in source form only, provided the news headers in "substantially
- * unaltered format" are retained, the introductory messages are not
- * removed, and no monies are exchanged.
- *
- * Permission is also granted to copy this source, without the
- * news headers, for the purposes of making an executable copy by
- * means of compilation, provided that such copy will not be used
- * for the purposes of competition in any othello tournaments, without
- * prior permission from the authors.
- *
- * No responsibility is taken for any errors on inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file), then an attempt will be made to fix them.
- */
-
- #include "reve.h"
- #include "color.h"
- #include "patchlevel.h"
- #include <ctype.h>
-
- #ifdef X11
- #include <X11/Xos.h>
- #endif /*X11*/
-
- #ifdef NO_TIMEVAL
- struct timeval {
- long tv_sec ; /* Seconds */
- long tv_usec ; /* Microseconds */
- } ;
- #endif /*NO_TIMEVAL*/
-
- /* Total amount of time (in minutes) to allow, at this level of difficulty.
- * The time allocation function is not used at level 1.
- */
-
- int timevals[MAXDIFF] = { 0, 1, 3, 5, 10, 15, 20, 30, 60 } ;
-
- char *diff_values[] = {
- " 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ", " 8 ", " 9 ", NULL
- } ;
-
- char *comp_plays[] = { NULL, NULL, "neither", "both" } ;
- char *notes_values[] = { "off", "on", NULL } ;
- char *player_values[] = { "human", "computer", NULL } ;
-
- char *resources[] = { /* Reve X resources read. */
- "animate", /* Boolean: show animation. */
- "bestmove", /* Boolean: show computer best move so far. */
- "boardSize", /* Integer: initial size of the reve game board. */
- "showClocks", /* Boolean: show clocks for each player. */
- "difficulty", /* Integer: difficulty level. */
- "last", /* Boolean: show last move (with a square). */
- "showLegalMoves", /* Boolean: invalid moves shows legal moves. */
- "log", /* Boolean: write computer info to log file. */
- "notes", /* Boolean: show computer notes. */
- "number", /* Boolean: show last move (number on stone). */
- "quick", /* Boolean: play quick game (don't flip stones). */
- "panelColor", /* String: main and property panels color. */
- "boardColor", /* String: playing board color. */
- "boardBorderColor", /* String: playing board border color. */
- "gridColor", /* String: grid lines color. */
- "textColor", /* String: text color. */
- "itemColor", /* String: color of the panel items. */
- "blackStoneColor", /* String: "black" stone color. */
- "whiteStoneColor", /* String: "white" stone color. */
- "properties", /* Boolean: initially show property window? */
- "showHelp", /* Boolean: initially show help window? */
- "boldFont", /* String: bold font. */
- "boardFont", /* String: game board font. */
- "helpFont", /* String: help font. */
- "normalFont", /* String: normal font. */
- "blackStoneName", /* String: name for "black" stone messages. */
- "whiteStoneName", /* String: name for "white" stone messages. */
- "printCommand", /* String: command to use to print games. */
- "iconiseForOpponentMove", /* Boolean: close reve window for opponent move.*/
- "bellAfterOpponentMove", /* Boolean: sound bell after opponent move. */
- "raiseAfterOpponentMove" /* Boolean: raise window after opponent move. */
- } ;
-
- enum cantype cmode, last_cmode ;
- enum disp_type dtype ;
- enum gr_type gtype ; /* Graphics type. */
- enum set_type direction ; /* Incremental direction for cycle item. */
- enum win_type curwin ; /* Window the current event for in. */
-
- FILE *hfp ; /* File descriptor for online help file. */
-
- char *colstr[REVE_COLORSIZE] = {
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
- } ;
-
- int rcols[REVE_COLORSIZE] ; /* Red colormap values. */
- int gcols[REVE_COLORSIZE] ; /* Green colormap values. */
- int bcols[REVE_COLORSIZE] ; /* Blue colormap values. */
-
- int tx, ty, tw, th ; /* Position and size of text field. */
-
- int piece_x ; /* Current X position of moving piece. */
- int piece_y ; /* Current Y position of moving piece */
-
- int bborder ; /* Size of the reve game board border. */
- int best_cmove ; /* Best computer move so far. */
- int board_height ; /* Height of the reve game board in pixels. */
- int board_width ; /* Width of the reve game board in pixels. */
- int but_inverted ; /* Value of panel item inverted. */
- int cell_height ; /* Height of an individual game board square. */
- int cell_width ; /* Width of an individual game board square. */
- int cmove_depth ; /* Depth of the current best computer move. */
- int color ; /* Current color value. */
- int cur_ch ; /* Current character pressed. */
- int curx ; /* Current mouse X position. */
- int cury ; /* Current mouse Y position. */
- int debug ; /* If set, prints out various debug messages. */
- int down ; /* Indicates is a mouse button is down. */
- int first_move = 0 ; /* Set if computer plays first move. */
- int iconic ; /* Set if window is currently iconic. */
- int help_height ; /* Height of the help window. */
- int help_showing ; /* If set, the help window is visible. */
- int help_width ; /* Width of the help window. */
- int inv_video = 0 ; /* Set if displaying in inverse video. */
- int invalid ; /* Set if last move was invalid. */
- int isblack ; /* Set if human to play the black pieces. */
- int iscolor ; /* Set if this is a color screen. */
- int isremote ; /* Set if playing remote user@host. */
- int iswhite ; /* Set if human to play the white pieces. */
- int itemno ; /* Current panel item being processed. */
- int item_value ; /* Value for current panel item. */
- int ix ; /* Initial X position of the icon. */
- int iy ; /* Initial Y position of the icon. */
- int last_move ; /* Last valid computer move. */
- int last_outline ; /* Position of last piece outline whilst dragging. */
- int level ; /* Current level of difficulty for computer moves. */
- int loadgame = 0 ; /* Set if there is a game file to load. */
- int lsval = 0 ; /* Set to 'l' or 's', if loading or saving. */
- int monochrome = 0 ; /* If set, display will be in monochrome. */
- int move ; /* Current move being evaluated. */
- int move_delta ; /* Delta for piece animation. */
- int nextc ; /* Current event identifier. */
- int next_player ; /* Next player (BLACK or WHITE) to move. */
- int old_diffval ; /* Old difficulty value (possibly restored). */
- int opp_bell ; /* If set, sound bell after opponents move. */
- int opp_iconise ; /* If set, close reve window for opponents move. */
- int opp_raise ; /* If set, auto raise window after opponent move. */
- int pid ; /* Process id of the reve_proc process. */
- int pieceXmargin ; /* X margin between piece and cell width. */
- int pieceXrad ; /* X radius of board piece. */
- int pieceYmargin ; /* Y margin between piece and cell height. */
- int pieceYrad ; /* Y radius of board piece. */
- int pipe_io[2][2] ;
- int play_computer ; /* Set if playing against the computer. */
- int posspec ; /* Set if -Wp or -g option is present (for X11) */
- int processing ; /* If set, opponent is processing a move. */
- int props_showing ; /* If set, the property window is visible. */
- int restore_moves ; /* Indicates if legal moves should be reshown. */
- int saveres = 0 ; /* If set, save computer results to log file. */
- int show_moves ; /* If set, all possible moves are being shown. */
- int snote ; /* Note value for current suggestion. */
- int socketfd ; /* Socket no. for user@host. */
- int sstate ; /* State of suggestion (showing/not showing). */
- int started ; /* Set just before window is displayed. */
- int suggestion = -1 ; /* Positive if a suggested move. */
- int tinput = 0 ; /* Set, when getting text input for load/save. */
- int validkey ; /* Set if half way though a valid multiple key. */
- int wx ; /* Initial X position of the window. */
- int wy ; /* Initial Y position of the window. */
- int xdebug ; /* If set, turns on debugging in the X11 driver. */
-
- time_t last_btime ; /* Last black time value. */
- time_t last_wtime ; /* Last white time value. */
- time_t start_time ; /* Start time for current move. */
-
- int font_heights[MAXFONTS] ; /* Height of all fonts used. */
- long help_offsets[MAXPAGES] ; /* Offsets into the reve help file. */
-
- /* Globals for passing arguments to "sandwich";
- * this is to save time putting arguments on and off the
- * stack in a very heavily used piece of code
- */
-
- int s_flip ;
- int s_move ;
- int s_opponent ;
- int s_player ;
- int s_row ;
- int s_col ;
-
- struct timeval tp ; /* Used by the nap_upto routine. */
-
- BOARD old_board ; /* The previous reve board. */
- BOARD board ; /* The current reve board. */
- BOARD *s_pos ;
- BOARD s_all ; /* List of valid positions for this move. */
-
- BOARD moves[64] ; /* Complete array of board moves. */
-
- struct iteminfo items[MAXITEMS] = { /* Panel items. */
-
- /* wtype type lx ly Items for control panel window.
- * label
- * x y
- * width height text value
- * options nopts
- * function
- */
-
- { /* load button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "load", 0,
- (char **) NULL, 0,
- draw_textfield
- },
-
- { /* moves? button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (1*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "moves?", 0,
- (char **) NULL, 0,
- show_all_moves
- },
-
- { /* new game button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "new game", 0,
- (char **) NULL, 0,
- new_game
- },
-
- { /* help button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "help...", 0,
- (char **) NULL, 0,
- do_help
- },
-
- { /* redo button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (4*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "redo", 0,
- (char **) NULL, 0,
- redo
- },
-
- { /* props button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (5*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "props...", 0,
- (char **) NULL, 0,
- do_props
- },
-
- { /* save button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "save", 0,
- (char **) NULL, 0,
- draw_textfield
- },
-
- { /* suggest button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (1*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "suggest", 0,
- (char **) NULL, 0,
- suggest
- },
-
- { /* print button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "print", 0,
- (char **) NULL, 0,
- print_game
- },
-
-
- { /* stop button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- /* BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)), */
- -1, -1,
- BWIDTH, BHEIGHT, "stop", 0,
- (char **) NULL, 0,
- do_stop
- },
-
- { /* undo button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (4*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "undo", 0,
- (char **) NULL, 0,
- undo
- },
-
- { /* cancel button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- -1, -1, /* Not normally active. */
- BWIDTH, BHEIGHT, "cancel", 0,
- (char **) NULL, 0,
- remove_textfield
- },
-
- { /* quit button. */
- W_PANEL, P_BUTTON, 0, 0,
- "",
- BBORDER + (5*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)),
- BWIDTH, BHEIGHT, "quit", 0,
- (char **) NULL, 0,
- destroy_reve
- },
-
- { /* Black player message item. */
- W_PANEL, P_MESSAGE,
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (2*(BHEIGHT+BGAP)),
- "Black:",
- BBORDER + (1*(BWIDTH+BGAP)), BBORDER + (2*(BHEIGHT+BGAP)),
- CWIDTH, CHEIGHT, "", 0,
- (char **) NULL, 0,
- NULL
- },
-
- { /* White player message item. */
- W_PANEL, P_MESSAGE,
- BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (2*(BHEIGHT+BGAP)),
- "White:",
- BBORDER + (4*(BWIDTH+BGAP)), BBORDER + (2*(BHEIGHT+BGAP)),
- CWIDTH, CHEIGHT, "", 1,
- (char **) NULL, 0,
- NULL
- },
-
- { /* Black player time left item. */
- W_PANEL, P_CLOCK,
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (3*(BHEIGHT+BGAP)),
- "Time left:",
- BBORDER + (1*(BWIDTH+BGAP)), BBORDER + (3*(BHEIGHT+BGAP)),
- 0, 0, "", 1,
- (char **) NULL, 0,
- NULL
- },
-
- { /* White player time left item. */
- W_PANEL, P_CLOCK,
- BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (3*(BHEIGHT+BGAP)),
- "Time left:",
- BBORDER + (4*(BWIDTH+BGAP)), BBORDER + (3*(BHEIGHT+BGAP)),
- 0, 0, "", 1,
- (char **) NULL, 0,
- NULL
- },
-
- { /* Panel message item. */
- W_PANEL, P_MESSAGE, 0, 0,
- "",
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (4*(BHEIGHT+BGAP)),
- 0, 0, "Use left mouse button to move", 0,
- (char **) NULL, 0,
- NULL
- },
-
- { /* Notes message item. */
- W_PANEL, P_MESSAGE, 0, 0,
- "",
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (5*(BHEIGHT+BGAP)),
- 0, 0, "", 0,
- (char **) NULL, 0,
- NULL
- },
-
- { /* Score message item. */
- W_PANEL, P_MESSAGE, 0, 0,
- "",
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (6*(BHEIGHT+BGAP)),
- 0, 0, "Black: 2, White: 2", 0,
- (char **) NULL, 0,
- NULL
- },
-
- { /* Turn message item. */
- W_PANEL, P_MESSAGE, 0, 0,
- "",
- BBORDER + (3*(BWIDTH+BGAP)), BBORDER + (6*(BHEIGHT+BGAP)),
- 0, 0, "", 0,
- (char **) NULL, 0,
- NULL
- },
-
- /* wtype type Property window items.
- * lx ly
- * label
- * x y
- * width height text value
- * options nopts
- * function
- */
-
- { /* Computer plays choice item. */
- W_PROPS, P_CHOICE,
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
- "Computer plays:",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (0*(BHEIGHT+BGAP)),
- 0, 0, "", 0,
- (char **) comp_plays, 4,
- set_option
- },
-
- { /* Difficulty choice item. */
- W_PROPS, P_CHOICE,
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)),
- "Difficulty:",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (1*(BHEIGHT+BGAP)),
- 0, 0, "", 0,
- (char **) diff_values, 9,
- set_option
- },
-
- { /* Set search depth cycle item. */
- W_PROPS, P_CYCLE,
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (2*(BHEIGHT+BGAP)),
- "Set search depth:",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (2*(BHEIGHT+BGAP)),
- 0, 0, "", 0,
- (char **) NULL, 0,
- set_option
- },
-
- { /* Options (Animate Move) item. */
- W_PROPS, P_TOGGLE,
- BBORDER + (0*(BWIDTH+BGAP)), BBORDER + (3*(BHEIGHT+BGAP)),
- "Options:",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (3*(BHEIGHT+BGAP)),
- TICKWIDTH, TICKHEIGHT, "Animate Move", 0,
- (char **) NULL, 0,
- set_option
- },
-
- { /* Options (Show Current Best Move) item. */
- W_PROPS, P_TOGGLE, 0, 0,
- "",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (4*(BHEIGHT+BGAP)),
- TICKWIDTH, TICKHEIGHT, "Show Current Best Move", 0,
- (char **) NULL, 0,
- set_option
- },
-
- { /* Options (Show Last Move) item. */
- W_PROPS, P_TOGGLE, 0, 0,
- "",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (5*(BHEIGHT+BGAP)),
- TICKWIDTH, TICKHEIGHT, "Show Last Move", 0,
- (char **) NULL, 0,
- set_option
- },
-
- { /* Options (Show Evaluation Info.) item. */
- W_PROPS, P_TOGGLE, 0, 0,
- "",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (6*(BHEIGHT+BGAP)),
- TICKWIDTH, TICKHEIGHT, "Show Evaluation Info.", 0,
- (char **) NULL, 0,
- set_option
- },
-
- { /* Options (Number Last Move) item. */
- W_PROPS, P_TOGGLE, 0, 0,
- "",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (7*(BHEIGHT+BGAP)),
- TICKWIDTH, TICKHEIGHT, "Number Last Move", 0,
- (char **) NULL, 0,
- set_option
- },
-
- { /* Options (Don't Show Flip) item. */
- W_PROPS, P_TOGGLE, 0, 0,
- "",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (8*(BHEIGHT+BGAP)),
- TICKWIDTH, TICKHEIGHT, "Don't Show Flip", 0,
- (char **) NULL, 0,
- set_option
- },
-
- { /* Options (Invalid Move Shows Legal Moves) item. */
- W_PROPS, P_TOGGLE, 0, 0,
- "",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (9*(BHEIGHT+BGAP)),
- TICKWIDTH, TICKHEIGHT, "Invalid Move Shows Legal Moves", 0,
- (char **) NULL, 0,
- set_option
- },
-
- { /* Options (Use clocks to time moves) item. */
- W_PROPS, P_TOGGLE, 0, 0,
- "",
- BBORDER + (2*(BWIDTH+BGAP)), BBORDER + (10*(BHEIGHT+BGAP)),
- TICKWIDTH, TICKHEIGHT, "Use Clocks to Time Moves", 0,
- (char **) NULL, 0,
- set_option
- },
-
- { /* Help window page cycle. */
- W_HELP, P_CYCLE,
- BBORDER + (0*(BWIDTH+BGAP)), CGAP,
- "Page",
- BBORDER + (1*(BWIDTH+BGAP)), CGAP,
- 0, 0, "", 1,
- (char **) NULL, 0,
- display_help
- },
- } ;
-
- char geometry[MAXLINE] ; /* X11 geometry information. */
-
- char *bstone_name ; /* "Black" stone name for messages. */
- char *display = NULL ; /* X11 display information. */
- char *fontnames[MAXFONTS] ; /* Font names (via X resources). */
- char edgefile[MAXLINE] ; /* Location of the reve edge table file. */
- char gamefile[MAXLINE] ; /* Name of file for load/save. */
- char helpfile[MAXLINE] ; /* Location of the reve online help file. */
- char line[40] ;
- char *myname ; /* user@host for this local person. */
- char *opponent ; /* user@host for remote networked person. */
- char *printcommand ; /* Command for printing the game. */
- char progname[MAXLINE] ; /* The name of this program. */
- char reveproc[MAXLINE] ; /* Pathname of the reve_proc program. */
- char *white_dpy ; /* White piece display information. */
- char *wstone_name ; /* "White" stone name for messages. */
-
- /* REVE global variables */
-
- int damier[NIVEAUMAX][64] ; /* Boards at different depth level */
- int tacouleur, macouleur ; /* Your and my colors during evaluation */
- int mnb, profmax ; /* Number of moves played, current max. depth */
- int max_depth = 2 ; /* Computer strategy - maximum depth. */
- int vp0, vo0 ; /* Current mobility components */
- long c1, c2, c3 ; /* Constants used in evaluation function */
- long edges[6561] ; /* Edges Stability Table */
- long note ; /* Note value for current computer move. */
- time_t timeleft ; /* Amount of time left for computer moves. */
-
- extern enum gr_type gtype ; /* Graphics type. */
-
-
- int
- main(argc, argv)
- int argc ;
- char *argv[] ;
- {
- STRCPY(progname, argv[0]) ; /* Save program name for later use. */
- STRCPY(gamefile, "reve.game") ;
- SPRINTF(line, " Reve. V1.3.%1d", PATCHLEVEL) ;
- get_display(argc, argv) ; /* Get possible X11 display information. */
- init_graphics(&argc, argv) ;
- reve_colorsetup(rcols, gcols, bcols) ; /* Setup default colors. */
- initialise() ; /* Initialise variables used by reve. */
- load_resources() ; /* Get resources from various places. */
- read_resources() ; /* Read resources from merged database. */
- get_options(argc, argv) ; /* Read command line options. */
- init_clocks() ; /* Setup timer clocks. */
- init_help_file(helpfile) ; /* Load reve help file page offsets. */
- set_display_types() ; /* Work out what displays to initialise. */
- if (init_ws_type()) /* Determine window system type. */
- {
- FPRINTF(stderr,"Error initialising window system.\n") ;
- exit(1) ;
- }
- generate_graphics(argc, argv) ;
- #ifdef REMOTE_PLAYER
- if (isremote) /* Do we need to get remote connection? */
- {
- get_addrs(myname, opponent) ;
- open_ctl() ;
- open_socket() ;
- start_msgs() ;
- if (is_local()) set_config(dtype) ; /* Reconfigure. */
- else invite_remote() ;
- end_msgs() ;
- message(PANEL_MES, "Connection established") ;
- beep() ;
- }
- #endif /* REMOTE_PLAYER */
- connect_io() ;
- if (!isremote && dtype != XBOTH) load_and_move() ;
- reset_clock(BLACK) ;
- reset_clock(WHITE) ;
- started = 1 ;
- start_tool(dtype) ; /* Event handling loop. */
- exit(0) ;
- /*NOTREACHED*/
- }
-
-
- void
- do_opponent_move(player)
- int player ;
- {
- set_cursor(CANVASCUR) ;
- if (ANIMATION) animate_move(move) ;
- if (best_cmove != -1 && DO_BESTMOVE) draw_square(best_cmove, IS_OFF, 2) ;
- do_move(player) ;
- last_move = move ;
- cmode = (enum cantype) (OPPONENT(player) + 1) ;
- }
-
-
- void
- generate_graphics(argc, argv)
- int argc ;
- char *argv[] ;
- {
- make_icon() ;
- make_frame(argc, argv) ; /* Create reve window/icon. */
- init_fonts() ; /* Load normal and bold fonts. */
- make_help_window(argc, argv) ; /* Make help window based on normal font. */
- make_canvas() ; /* Create drawing canvas. */
- make_pieces(board_width, board_height) ;
- initboard() ;
- set_cursor(CANVASCUR) ;
- }
-
-
- void
- initialise() /* Initialise various variable used by reve. */
- {
- int i ;
-
- cury = wx = wy = ix = iy = 0 ;
- bborder = BBORDER ;
- board_height = BOARD_DIM ; /* Initial board size. */
- board_width = BOARD_DIM ;
- play_computer = 1 ; /* Default is human vs computer. */
- iconic = 0 ; /* Initially an open window. */
- invalid = FALSE ;
- last_move = -1 ;
- last_outline = -1 ;
- next_player = BLACK ;
- best_cmove = -1 ;
- but_inverted = -1 ;
- debug = FALSE ;
- xdebug = FALSE ;
- help_showing = FALSE ; /* Help window not visible. */
- opp_bell = FALSE ; /* Don't sound bell after opponents move. */
- opp_iconise = FALSE ; /* Don't close reve window for opponents move. */
- opp_raise = FALSE ; /* Don't auto raise window after opponent move. */
- processing = FALSE ; /* No computer move initially. */
- props_showing = FALSE ; /* Properties window not visible. */
- started = FALSE ;
- validkey = 0 ;
- cmode = BLACK_START ;
- show_moves = FALSE ;
- sstate = IS_OFF ;
- isblack = 0 ;
- isremote = 0 ;
- iswhite = 0 ;
- level = INIT_DEPTH ;
- items[(int) DIFF_CHOICE].value = old_diffval = level - 1 ;
-
- read_str(&myname, getuserhost()) ; /* user@host for this person. */
- opponent = NULL ; /* No networked game by default. */
-
- pipe_io[0][0] = pipe_io[0][1] = pipe_io[1][0] = pipe_io[1][1] = -1 ;
- socketfd = -1 ;
-
- for (i = 0; i < MAXFONTS; i++) fontnames[i] = NULL ;
-
- read_str(&bstone_name, "Black") ; /* Default names for messages. */
- read_str(&wstone_name, "White") ;
- read_str(&comp_plays[0], "white") ; /* Computer plays: property item. */
- read_str(&comp_plays[1], "black") ;
- read_str(&printcommand, "trans | lpr") ; /* Default print command. */
-
- STRCPY(geometry, "") ; /* X11 geometry information. */
- STRCPY(edgefile, EDGENAME) ;
- STRCPY(helpfile, HELPNAME) ;
- STRCPY(reveproc, REVEPROC) ;
- }
-
-
- void
- read_resources() /* Read all possible resources from database. */
- {
- int boolval, intval, len, n ;
- char str[MAXLINE] ;
-
- if (get_bool_resource(R_ANIMATE, &boolval)) ANIMATION = boolval ;
- if (get_bool_resource(R_BESTMOVE, &boolval)) DO_BESTMOVE = boolval ;
-
- if (get_int_resource(R_BOARDSIZE, &intval))
- {
- if (intval < MINBOARDSIZE) intval = MINBOARDSIZE ;
- if (intval > MAXBOARDSIZE) intval = MAXBOARDSIZE ;
- board_width = board_height = intval ;
- }
-
- if (get_int_resource(R_DIFFICULTY, &intval))
- {
- level = intval ;
- if (level < 1 || level > MAXDIFF) level = INIT_DEPTH ;
- items[(int) DIFF_CHOICE].value = old_diffval = level - 1 ;
- }
-
- if (get_bool_resource(R_CLOCK, &boolval)) DO_CLOCK = boolval ;
- if (get_bool_resource(R_LAST, &boolval)) DO_LAST = boolval ;
- if (get_bool_resource(R_LOG, &boolval)) saveres = boolval ;
- if (get_bool_resource(R_LEGALMOVE, &boolval)) SHOW_LEGAL = boolval ;
- if (get_bool_resource(R_NOTES, &boolval)) SHOW_NOTES = boolval ;
- if (get_bool_resource(R_NUMBER, &boolval)) DO_NUMBER = boolval ;
- if (get_bool_resource(R_QUICK, &boolval)) QUICKGAME = boolval ;
- if (get_bool_resource(R_PROPS, &boolval)) props_showing = boolval ;
- if (get_bool_resource(R_HELP, &boolval)) help_showing = boolval ;
-
- if (get_bool_resource(R_OPPICON, &boolval)) opp_iconise = boolval ;
- if (get_bool_resource(R_OPPBELL, &boolval)) opp_bell = boolval ;
- if (get_bool_resource(R_OPPRAISE, &boolval)) opp_raise = boolval ;
-
- if (get_str_resource(R_PANELC, str)) read_str(&colstr[C_PANEL], str) ;
- if (get_str_resource(R_BOARDC, str)) read_str(&colstr[C_SQUARE], str) ;
- if (get_str_resource(R_BOARDBC, str)) read_str(&colstr[C_BORDER], str) ;
- if (get_str_resource(R_GRIDC, str)) read_str(&colstr[C_GRID], str) ;
- if (get_str_resource(R_TEXTC, str)) read_str(&colstr[C_TEXT], str) ;
- if (get_str_resource(R_ITEMC, str)) read_str(&colstr[C_ITEMS], str) ;
- if (get_str_resource(R_BSTONEC, str)) read_str(&colstr[C_BSTONE], str) ;
- if (get_str_resource(R_WSTONEC, str)) read_str(&colstr[C_WSTONE], str) ;
- if (get_str_resource(R_PCMD, str)) read_str(&printcommand, str) ;
-
- if (get_str_resource(R_BFONT, str)) read_str(&fontnames[(int) BFONT], str) ;
- if (get_str_resource(R_GFONT, str)) read_str(&fontnames[(int) GFONT], str) ;
- if (get_str_resource(R_HFONT, str)) read_str(&fontnames[(int) HFONT], str) ;
- if (get_str_resource(R_NFONT, str)) read_str(&fontnames[(int) NFONT], str) ;
-
- if (get_str_resource(R_BSTONEN, str))
- {
- read_str(&bstone_name, str) ;
- STRCPY(items[(int) BLACK_PLAYS].label, str) ;
- len = strlen(str) ;
- for (n = 0; n < len; n++)
- if (isupper(str[n])) str[n] = tolower(str[n]) ;
- read_str(&comp_plays[1], str) ;
- }
- if (get_str_resource(R_WSTONEN, str))
- {
- read_str(&wstone_name, str) ;
- STRCPY(items[(int) WHITE_PLAYS].label, str) ;
- len = strlen(str) ;
- for (n = 0; n < len; n++)
- if (isupper(str[n])) str[n] = tolower(str[n]) ;
- read_str(&comp_plays[0], str) ;
- }
- }
-
-
- void
- read_str(str, value)
- char **str, *value ;
- {
- if (*str != NULL) (void) free(*str) ;
- if (value != NULL && strlen(value))
- {
- *str = (char *) malloc((unsigned) (strlen(value) + 1)) ;
- STRCPY(*str, value) ;
- }
- else *str = NULL ;
- }
-
-
- void
- set_config(dtype)
- enum disp_type dtype ;
- {
- int val ;
-
- if (isremote)
- if (dtype == XWHITE)
- {
- STRCPY(items[(int) BLACK_PLAYS].text, opponent) ;
- STRCPY(items[(int) WHITE_PLAYS].text, myname) ;
- processing = TRUE ;
- set_cursor(HOURGLASS) ;
- }
- else
- {
- STRCPY(items[(int) BLACK_PLAYS].text, myname) ;
- STRCPY(items[(int) WHITE_PLAYS].text, opponent) ;
- }
-
- isblack = iswhite = 0 ;
- if (dtype == XBLACK) isblack = 1 ;
- else if (dtype == XWHITE) iswhite = first_move = 1 ;
- else if (dtype == XBOTH) isblack = iswhite = 1 ;
-
- val = (isblack == 0) ;
- items[(int) BLACK_PLAYS].value = val ;
- if (!isremote) STRCPY(items[(int) BLACK_PLAYS].text, player_values[val]) ;
-
- val = (iswhite == 0) ;
- items[(int) WHITE_PLAYS].value = val ;
- if (!isremote) STRCPY(items[(int) WHITE_PLAYS].text, player_values[val]) ;
-
- if (isremote) items[(int) COMP_CHOICE].value = CP_NEITHER ;
- else if (dtype == XBLACK) items[(int) COMP_CHOICE].value = CP_WHITE ;
- else if (dtype == XWHITE) items[(int) COMP_CHOICE].value = CP_BLACK ;
- else if (dtype == XBOTH) items[(int) COMP_CHOICE].value = CP_NEITHER ;
- }
-
-
- /* Work out, who plays what. There are a fair number of combinations.
- * This table hopefully gives the setup information for each combination.
- *
- * NOTE: This could easily be done with less tests; instead the routine is
- * written for clarity.
- *
- * | BLACK WHITE OPPONENT
- * |---------------------------
- * |A - - - black on local, white is computer.
- * |B - - user@host black on local, white on remote.
- * |C - - computer black on local, white is computer.
- * |D - SET - white on local, black is computer.
- * |E - SET user@host black on remote, white on local.
- * |F - SET computer black is computer, white is local.
- * |G SET - - black on local, white is computer.
- * |H SET - user@host black on local, white on remote.
- * |I SET - computer black on local, white is computer.
- * |J SET SET - both on local display.
- * |K SET SET user@host black on local, white on remote.
- * |L SET SET computer black on local, white is computer.
- */
-
- void
- set_display_types()
- {
- if (!isblack && !iswhite && !opponent) /* A */
- {
- dtype = XBLACK ;
- isremote = 0 ;
- }
- else if (!isblack && !iswhite && opponent && !play_computer) /* B */
- {
- dtype = XBLACK ;
- isremote = 1 ;
- }
- else if (!isblack && !iswhite && opponent && play_computer) /* C */
- {
- dtype = XBLACK ;
- isremote = 0 ;
- }
- else if (!isblack && iswhite && !opponent) /* D */
- {
- dtype = XWHITE ;
- isremote = 0 ;
- }
- else if (!isblack && iswhite && opponent && !play_computer) /* E */
- {
- dtype = XWHITE ;
- isremote = 1 ;
- }
- else if (!isblack && iswhite && opponent && play_computer) /* F */
- {
- dtype = XWHITE ;
- isremote = 0 ;
- }
- else if ( isblack && !iswhite && !opponent) /* G */
- {
- dtype = XBLACK ;
- isremote = 0 ;
- }
- else if ( isblack && !iswhite && opponent && !play_computer) /* H */
- {
- dtype = XBLACK ;
- isremote = 1 ;
- }
- else if ( isblack && !iswhite && opponent && play_computer) /* I */
- {
- dtype = XBLACK ;
- isremote = 0 ;
- }
- else if ( isblack && iswhite && !opponent) /* J */
- {
- dtype = XBOTH ;
- isremote = 0 ;
- play_computer = 1 ;
- }
- else if ( isblack && iswhite && opponent && !play_computer) /* K */
- {
- dtype = XBLACK ;
- isremote = 1 ;
- }
- else if ( isblack && iswhite && opponent && play_computer) /* L */
- {
- dtype = XBLACK ;
- isremote = 0 ;
- }
- set_config(dtype) ;
- }
-
-
- void
- usage()
- {
- FPRINTF(stderr, "%s version 1.3.%1d\n\n", progname, PATCHLEVEL) ;
- FPRINTF(stderr, "Usage: %s: [-animate] [-bestmove] ", progname) ;
- FPRINTF(stderr, "[-black] [-clock] [-d difficulty]\n") ;
- FPRINTF(stderr, "\t[-e edgefile] [-g geometry] [-h helpfile] [-help]\n") ;
- FPRINTF(stderr, "\t[-i] [-last] [-load gamefile] [-log] [-m] [-notes]\n") ;
- FPRINTF(stderr, "\t[-number] [-props] [-quick] [-r reve_proc] [-v]\n") ;
- FPRINTF(stderr, "\t[-white] [-?] [-Wi] [-Wp x y] [-WP x y]\n") ;
- }
-
-
- #ifdef NO_USLEEP
- usleep(x) /* Suspend execution for interval in microseconds. */
- unsigned x ;
- {
- #ifdef NOSELECT
- unsigned seconds = x / 1000 ;
-
- if (x > 0) sleep(x) ;
- #else
-
- struct timeval st_delay ;
-
- st_delay.tv_usec = x ;
- st_delay.tv_sec = 0 ;
- (void) select(32, NULL, NULL, NULL, &st_delay) ;
- #endif /*NOSELECT*/
- }
- #endif /*NO_USLEEP*/
-